﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using MySql.Data.MySqlClient;

namespace MySQL.Db
{
    public class QueryArguments : Collection<MySqlParameter>
    {
        public QueryArguments()
        {
        }

		public MySqlParameter Add(string name, string value)
		{
			var v = new MySqlParameter(name, MySqlDbType.VarChar) { Value = value ?? (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, bool? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.Int16) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, short? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.Int16) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, ushort? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.UInt16) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, int? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.Int32) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, uint? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.UInt32) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, long? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.Int64) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, ulong? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.UInt64) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, decimal? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.Decimal) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, DateTime? value)
		{
			var v = new MySqlParameter(name, MySqlDbType.DateTime) { Value = value.HasValue ? value.Value : (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		public MySqlParameter Add(string name, byte[] value)
		{
			var v = new MySqlParameter(name, MySqlDbType.VarBinary) { Value = value ?? (object)DBNull.Value };
			this.Add(v);
			return v;
		}

		/*
        public void Add(string name, object value, MySqlDbType type)
        {
            this.Add(QueryArguments.CreateArgument(name, value, type, ParameterDirection.Input));
        }

        public void Add(string name, object value, MySqlDbType type, ParameterDirection direction)
        {
            this.Add(QueryArguments.CreateArgument(name, value, type, direction));
        }

        public static MySqlParameter CreateArgument(string name, object value, MySqlDbType type)
        {
            return CreateArgument(name, value, type, ParameterDirection.Input);
        }

        public static MySqlParameter CreateArgument(string name, object value, MySqlDbType type, ParameterDirection direction)
        {
            MySqlParameter arg = new MySqlParameter(name, type);
            arg.Direction = direction;
            arg.Value = value;

            return arg;
        }
		 */

		internal void All(Func<MySqlParameter, bool> func)
		{
			throw new NotImplementedException();
		}
	}
}